<template>
  <div class="AlbumDetail" v-if="detail">
    <div class="Top">
      <img v-lazy="detail.album.picUrl" alt="" />
      <div class="right">
        <div class="title">
          <span>专辑</span>
          <span>{{ detail.album.name }}</span>
        </div>
        <MyButton :list="detail.songs"></MyButton>
        <div class="artist">
          <span>歌手：</span>
          <span @click="itemClick(detail.album.artist.id)">{{ detail.album.artist.name }}</span>
        </div>
        <div class="time">
          <span>时间：</span>
          <span>{{ detail.album.publishTime | dateFormat }}</span>
        </div>
      </div>
    </div>
    <Table :tableData="detail.songs" :config="config"></Table>
  </div>
</template>

<script>
import Table from '@/components/table/Table';
import MyButton from '@/components/mybutton/MyButton';
export default {
  data() {
    return {
      mid: '',
      detail: '',
      //表格参数配置
      config: {
        width: 300,
        showTodos: true,
        showAlbum: true,
      },
    };
  },
  components: { Table, MyButton },
  created() {
    this.mid = this.$route.params.mid;
    this.getAlbumDetail();
  },
  methods: {
    async getAlbumDetail() {
      const res = await this.$request('/album', { id: this.mid });
      this.detail = res;
    },
    itemClick(id) {
      this.$router.push('/artistdetail/' + id);
    },
  },
  watch: {
    '$route.params.mid'(mid) {
      if (!mid) return;
      this.mid = mid;
      this.getAlbumDetail();
    },
  },
};
</script>

<style scoped='scoped' lang='scss'>
.AlbumDetail {
  .Top {
    display: flex;
    img {
      @include image(200px, 5px);
      margin-right: 20px;
    }
    .right {
      > div {
        margin-bottom: 10px;
      }
      .title {
        display: flex;
        align-items: center;
        :first-child {
          @include tag;
        }
        :last-child {
          font-size: 22px;
          font-weight: 600;
        }
      }
      .artist {
        font-size: 12px;
        :last-child {
          color: $userBlue;
          cursor: pointer;
          &:hover {
            color: $userHover;
          }
        }
      }
      .time {
        font-size: 12px;
        :last-child {
          color: #919191;
        }
      }
    }
  }
}
</style>